package com.zhongying.sys.service.impl;

import com.zhongying.jf.ResConstants;
import com.zhongying.jf.exception.ZhongyingiException;
import com.zhongying.jf.result.Result;
import com.zhongying.jf.result.ResultSupport;
import com.zhongying.sys.dao.SysConfigDao;
import com.zhongying.sys.entity.SysConfigEntity;
import com.zhongying.sys.service.SysConfigService;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;

@Service("sysConfigService")
public class SysConfigServiceImpl implements SysConfigService {
	@Autowired
	private SysConfigDao sysConfigDao;
	
	@Override
	@CacheEvict(value="sysConfigCache",key="'SysConfigkey'")
	public void save(SysConfigEntity config) {
		sysConfigDao.save(config);
	}

	@Override
	@CacheEvict(value="sysConfigCache",key="'SysConfigkey'")
	public void update(SysConfigEntity config) {
		sysConfigDao.update(config);
	}

	@Override
	@CacheEvict(value="sysConfigCache",key="'SysConfigkey'")
	public void deleteBatch(Long[] ids) {
		sysConfigDao.deleteBatch(ids);
	}

	@Override
	public List<SysConfigEntity> queryList(Map<String, Object> map) {
		return sysConfigDao.queryList(map);
	}

	@Override
	public int queryTotal(Map<String, Object> map) {
		return sysConfigDao.queryTotal(map);
	}

	@Override
	public SysConfigEntity queryObject(Long id) {
		return sysConfigDao.queryObject(id);
	}

	@Override
	public String queryByCode2Key(String code, String key) {
		return null;
	}

	@Override
	@Cacheable(value="sysConfigCache",key="'SysConfigkey'")
	public List<SysConfigEntity> queryAll2Cache() {
		List<SysConfigEntity> list = sysConfigDao.queryList(new HashMap<>());
		Collections.sort(list);
		return list;
	}

	/**
	 * 业务线列表接口
	 *
	 * @return
	 * @throws ZhongyingiException
	 */
	@Override
	public Result getPlatform() throws ZhongyingiException {
		// 查询数据库
		List<Map> platformMap = sysConfigDao.getPlatform();

		Result result = new ResultSupport();
		result.setCode(ResConstants.SUCCESS.getCode());
		result.setMsg(ResConstants.SUCCESS.getMsg());
		result.setModel(platformMap);
		return result;
	}
}
